package com.wyz.tracing.utils;

import com.wyz.tracing.domain.entity.tracing.different.EntityDiff;
import de.danielbechler.diff.ObjectDifferBuilder;
import de.danielbechler.diff.node.DiffNode;

/**
 * @author wyz
 * @version 1.0
 * @date 2023/8/21
 */
public class DiffUtils {

    public static EntityDiff diff(Object snapshot, Object obj) {
        DiffNode diffNode = ObjectDifferBuilder.buildDefault().compare(obj, snapshot);

        if (!diffNode.hasChanges()) {
            return EntityDiff.EMPTY;
        }

        EntityDiff entityDiff = new EntityDiff();
        entityDiff.setHasChanges(true);
        diffNode.visit((node, visit) -> {
            boolean hasChanges = node.hasChanges();
            Object objValue = node.canonicalGet(obj);
            Object snapshotValue = node.canonicalGet(snapshot);
            // 处理其他的逻辑和构建EntityDiff对象
        });

        return entityDiff;
    }
}
